﻿using System;
using System.Diagnostics;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKRevitBase.WinForm;
using YJKPatternSign.StairsRoomPlanSign.ControlLayer;
using YJKPatternSign.StairsRoomSection.Manager;

namespace YJKPatternSign.StairsRoomSection
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	internal class CmdWallDetail : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			UIApplication application = commandData.Application;
			if (CmdWallDetail._hWndRevit == null)
			{
                CmdWallDetail._hWndRevit = new WindowHandle(Process.GetCurrentProcess().MainWindowHandle);
			}
			UIDocument activeUIDocument = commandData.Application.ActiveUIDocument;
			try
			{
				Reference reference = activeUIDocument.Selection.PickObject((Autodesk.Revit.UI.Selection.ObjectType)1, new DetailViewBlockSelectFilter(), "选择一个视图");
				new SectionStairsRoomManager(application, CmdWallDetail._hWndRevit, reference.ElementId, 3, null).Run();
			}
			catch (Exception)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public static WindowHandle _hWndRevit;
	}
}
